package rtti;

import framework.AbstractTest;
import utils.Log;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by shane on 2018/6/12.
 */

class CountedInteger {
    private static long counter;

    private final long id = counter++;

    public String toString() {
        return Long.toString(id);
    }
}

public class FilledList<T> extends AbstractTest {
    private Class<T> type;
    public FilledList(Class<T> type) {
        this.type = type;
    }


    public List<T> create(int n) {
        List<T> res = new ArrayList<T>();

        try {
            for (int i = 0; i < n; i++) {
                res.add(type.newInstance());
            }
        } catch (Exception e) {
            throw  new RuntimeException(e);
        }

        return res;
    }



    @Override
    public void test(String[] args) {
        super.test(args);

        FilledList<CountedInteger> fl = new FilledList<CountedInteger>(CountedInteger.class);

        Log.vn(fl.create(15).toString());
    }
}
